<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<!--潘天赐-->
<head>
    <meta charset="UTF-8">
    <title>Title</title>

    <script type="text/javascript" src="static/js/jquery.min.js"></script>
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap.min.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap.min.css" />
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap-treeview.min.css"
          th:href="@{static/js/bootstrap/css/bootstrap-treeview.min.css}"
    >
    <script src="static/js/bootstrap/js/bootstrap-treeview.min.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap.addtabs.css">
    <script src="static/js/bootstrap/js/bootstrap.addtabs.min.js"></script>
    <link rel="stylesheet" href="static//js/bootstrap/css/bootstrap-table.min.css">
    <script src="static/js/bootstrap/js/bootstrap-table.min.js"></script>
    <script src="static/js/bootstrap/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="static/js/bootstrap/js/bootbox.js"></script>
    <link rel="stylesheet"
          href="static/js/bootstrap/css/bootstrap-datetimepicker.min.css" />
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap-datetimepicker.min.js"></script>
    <script type="text/javascript"
            src="static/js/bootstrap/js/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="static/js/bootstrap-fileinput/js/fileinput.js"></script>
    <script src="static/js/bootstrap-fileinput/js/locales/zh.js"></script>
    <link rel="stylesheet" href="static/js/bootstrap-fileinput/css/fileinput.css">

</head>
<body>

<h4 style="color: #8c8c8c"><label>上传方案：</label></h4><br>
<form id="myForm">
    <div class="row" style="height: 420px">
        <input id="file‐Portrait" type="file" name="file">
        <input type="hidden" name="pictureName" id="fimg1">
        <input type="hidden" class="form-control" th:value="${orderReceivingQueryPictureId}" name="queryPictureId" id="queryPictureId">
        <input type="hidden" class="form-control" th:value="${orderReceivingProductId}" name="commonId" id="commonQueryId">
    </div>
</form>

<button type="button" onclick="addFile()" class="btn btn-success">确认上传</button>

<table class="table" id="myTable"></table>
<br><br>
<button type="button" onclick="filloutMaterials()" class="btn btn-primary">下一步 填写材料单</button>


</body>
<script>

    var id = $("#commonQueryId").val();
    $("#myTable").bootstrapTable({
        url:"queryPictureFile?id="+id,
        columns:[
            {field:'pictureId',title:'序号'},
            {field:'pictureName',title:'文件名称'},
            {field:'cz',title:'操作',
                formatter: function(value,row,index){
                        return '<button type="button" onclick="deleteFile('+row.pictureId+')" class="btn btn-link">删除</button>';
                }
            },
        ],
        pagination:true,			//是否展示分页
        pageNumber:1,				//当前页
        pageSize:3,					//默认每页条数
        pageList:[3,2,5],			//分页组件
        sidePagination : 'client',	//分页方式：client客户端分页，server服务端分页
    })

    function addFile(){
        $.ajax({
            url:"addFile",
            data:$("#myForm").serialize(),//获取表单的值
            success:function(){
                alert("成功")
                $("#myTable").bootstrapTable('refresh');//表格刷新
            }
        });
    }

    function deleteFile(id){
        $.ajax({
            url:"deleteFile",
            data: {id:id},
            success:function(){
                alert("成功")
                $("#myTable").bootstrapTable('refresh');//表格刷新
            }
        });
    }

    function filloutMaterials(){
        var commonQueryId = $("#commonQueryId").val();
        var id = $("#queryPictureId").val();
        location.href="JumpToMaterials?queryPictureId="+id+"&commonQueryId="+commonQueryId
    }

    //初始化fileinput控件（第一次初始化）//上传图片
    $('#file‐Portrait').fileinput({
        language: 'zh', //设置语言
        uploadUrl: "uploadFile", //上传的地址
        allowedFileExtensions : ['jpg', 'png','gif','word','xlsx','docx','txt'],//接收的文件后缀,
        maxFileCount: 100,
        enctype: 'multipart/form‐data',
        showUpload: true, //是否显示上传按钮
        showCaption: false,//是否显示标题
        browseClass: "btn btn‐primary", //按钮样式
        previewFileIcon: "<i class='glyphicon glyphicon‐king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
        success:function(data){
        }
//dropZoneEnabled: false,//是否显示拖拽区域
//minImageWidth: 50, //图片的最小宽度
//minImageHeight: 50,//图片的最小高度
//maxImageWidth: 1000,//图片的最大宽度
//maxImageHeight: 1000,//图片的最大高度
//maxFileSize: 0,//单位为kb，如果为0表示不限制文件大小
//minFileCount: 0,
// maxFileCount: 10, //表示允许同时上传的最大文件个数
// enctype: 'multipart/form‐data',
// validateInitialCount:true,24 // previewFileIcon: "<i class='glyphicon glyphicon‐king'></i>",
// msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",
    });
    $("#file‐Portrait").on("fileuploaded", function (event, data, previewId, index) {
        console.log(data.response);
        console.log(data.response.aa);
        //var dataJson = JSON.parse(data.response);
        $("#fimg1").val(data.response.aa);
    })
</script>
</html>